#include <stdio.h>
#include <stdlib.h>

#include <time.h>
#include <math.h>
#include <string.h>
#include <conio.h>

int vvod(int *n,int a[])
{
    printf("Vvedite N\n");
    scanf("%d", n);
    int   i;
    srand(time(0));
    for (i=0; i<*n; i++)
    {
        a[i]=rand()%10;     
    }
    
}

int printalt(int n, int a[])
{
    int i;
    for (i=0; i<n; i++) 
    {
        printf("a[%d]=%d ",i, a[i]);
    } 
    printf(" \n");
}



int qSort(int a[], int low, int high,int (*comp)(int,int))
{
    int i = low;                
    int j = high;
    int x = a[(low+high)/2];  
    int temp;
    do {
        while(-1==(*comp)(a[i] , x)) ++i;
        while(1==(*comp)(a[j] , x)) --j;  
        if(i <= j)
        {           
              temp = a[i];
              a[i] = a[j];
              a[j] = temp;
              i++; j--;
        }
      } while(i < j);
      if(low < j) qSort(a, low, j,comp);
      if(i < high) qSort(a, i, high,comp);
}

int compare(int a, int b)
{
    
    if(a<b) return -1;
    if(a>b) return 1; 
    if(a==b) return 0;   
}

int main()
{
    int n=10;
    
    int a[10000];
    int i;
    vvod(&n,a);
    printalt(n,a);
    
    qSort(a,0,n-1,&compare);
    printalt(n,a);
    _getch();
    return(0);
}
